class ScorePrintController {

    def index = { redirect(action: "print", params: params) }
//
    def print = {
         if (params.id) {
            [ classes : Classes.get(params.id) , term : Score.currentTerm()]
        }else{
            flash.message = "必须首先确定班级。"
        } 
    }

  
    // 开始打印
    def doprint = {
       
        def courses = params.course
        if (!courses in Object[]) {
            courses = [params.course]
        }
 
        def classes = Classes.get(params.classesId)

        // ==========================
        def scoreArray = []
        classes?.student?.each{ std->
            scoreArray.add(
             Score.withCriteria {
                and{
                    eq('student', std)
                    eq('team', params.team.toInteger())
                    eq('grade', params.grade.toInteger())
                    eq('term', params.term)
                    eq('year', Calendar.instance.get(Calendar.YEAR))
                }
            })
        }
 
        ['classes' : classes , "courses" : courses , 
        'term' : params.term ,'grade' : params.grade,'team' : params.team,
        'history': scoreArray]
    }

}
